﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MockupDesigner.Editors.ValidableEditors;

namespace MockupDesigner.Editors.Controls
{
    /// <summary>
    /// Interaction logic for WebPageEditor.xaml
    /// </summary>
    public partial class WebPageEditorControl : UserControl
    {
        public WebPageEditorControl(WebPageEditor editor)
        {
            InitializeComponent();
            this.editor = editor;
            this.IsVisibleChanged += new DependencyPropertyChangedEventHandler(WebPageEditorControl_IsVisibleChanged);
        }

        void WebPageEditorControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (!((bool)e.NewValue) && !isCancel)
                editor.Validate();
        }
        private WebPageEditor editor;

        public string Title
        {
            get { return TitleTB.Text; }
            set { TitleTB.Text = value; }
        }

        public string Address
        {
            get { return AddressTB.Text; }
            set { AddressTB.Text = value; }
        }

        private void OkBT_Click(object sender, RoutedEventArgs e)
        {
            editor.Validate();
        }

        private bool isCancel;
        private void CancelBT_Click(object sender, RoutedEventArgs e)
        {
            this.isCancel = true;
            editor.Cancel();
        }
    }


}
